<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.2.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/blog/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/blog/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/blog/images/logo.svg" color="#222">

<link rel="stylesheet" href="/blog/css/main.css">


<link rel="stylesheet" href="/blog/lib/font-awesome/css/all.min.css">
  <link rel="stylesheet" href="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"gitee.com","root":"/blog/","scheme":"Gemini","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"always","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":true,"show_result":true,"style":"mac"},"back2top":{"enable":true,"sidebar":false,"scrollpercent":true},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":true,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="JDBC(Java DataBase Connectivity)是Java和数据库之间的一个桥梁，是一个规范而不是一个实现，能够执行SQL语句。它由一组用Java语言编写的类和接口组成。各种不同类型的数据库都有相应的实现，本文中的代码都是采用Mysql数据库实现的。">
<meta property="og:type" content="article">
<meta property="og:title" content="JDBC详细介绍">
<meta property="og:url" content="https://gitee.com/Demon_wang/blog.git/post/42809/index.html">
<meta property="og:site_name" content="Demonの博客">
<meta property="og:description" content="JDBC(Java DataBase Connectivity)是Java和数据库之间的一个桥梁，是一个规范而不是一个实现，能够执行SQL语句。它由一组用Java语言编写的类和接口组成。各种不同类型的数据库都有相应的实现，本文中的代码都是采用Mysql数据库实现的。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://img-blog.csdn.net/20180729201036257?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0p1bmdsZV9SYW8=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70">
<meta property="article:published_time" content="2020-10-17T19:31:50.130Z">
<meta property="article:modified_time" content="2020-10-17T19:31:50.131Z">
<meta property="article:author" content="Demon">
<meta property="article:tag" content="blog">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://img-blog.csdn.net/20180729201036257?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0p1bmdsZV9SYW8=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70">

<link rel="canonical" href="https://gitee.com/Demon_wang/blog.git/post/42809/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>JDBC详细介绍 | Demonの博客</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

<link rel="alternate" href="/blog/atom.xml" title="Demonの博客" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/blog/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">Demonの博客</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">虚幻大千两茫茫，一邂逅，终难忘</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/blog/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/blog/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/blog/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/blog/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/blog/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
        <li class="menu-item menu-item-schedule">

    <a href="/blog/schedule/" rel="section"><i class="fa fa-calendar fa-fw"></i>日程表</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://gitee.com/Demon_wang/blog.git/post/42809/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/blog/images/Demon.jpg">
      <meta itemprop="name" content="Demon">
      <meta itemprop="description" content="博客">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Demonの博客">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          JDBC详细介绍
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2020-10-18 03:31:50" itemprop="dateCreated datePublished" datetime="2020-10-18T03:31:50+08:00">2020-10-18</time>
            </span>

          <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>7.5k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>7 分钟</span>
            </span>
            <div class="post-description">JDBC(Java DataBase Connectivity)是Java和数据库之间的一个桥梁，是一个规范而不是一个实现，能够执行SQL语句。它由一组用Java语言编写的类和接口组成。各种不同类型的数据库都有相应的实现，本文中的代码都是采用Mysql数据库实现的。</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h2 id="JDBC"><a href="#JDBC" class="headerlink" title="JDBC"></a>JDBC</h2><blockquote>
<p>JDBC(Java DataBase Connectivity)是Java和数据库之间的一个桥梁，是一个规范而不是一个实现，能够执行SQL语句。它由一组用Java语言编写的类和接口组成。各种不同类型的数据库都有相应的实现，本文中的代码都是采用Mysql数据库实现的。</p>
</blockquote>
<p><img src="https://img-blog.csdn.net/20180729201036257?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0p1bmdsZV9SYW8=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70" alt="JDBC"></p>
<h3 id="JDBC编程步骤"><a href="#JDBC编程步骤" class="headerlink" title="JDBC编程步骤"></a>JDBC编程步骤</h3><h4 id="1-装载相应的数据库的JDBC驱动并进行初始化"><a href="#1-装载相应的数据库的JDBC驱动并进行初始化" class="headerlink" title="1.装载相应的数据库的JDBC驱动并进行初始化"></a>1.装载相应的数据库的JDBC驱动并进行初始化</h4><blockquote>
<p>使用JDBC的步骤：<br>    1.初始化驱动：通过初始化驱动类com.mysql.jdvc.Driver,该类就在mysql-connector-java.jar中。oracle数据库驱动包是ojdbc6.jar。</p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">try</span>&#123;</span><br><span class="line">   Class.forName(<span class="string">&quot;com.mysql.jdbc.Driver&quot;</span>);</span><br><span class="line">&#125; <span class="keyword">catch</span> (ClassNotFoundException e) &#123;</span><br><span class="line">   e.printStackTrace(); </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>Class.forName是把这个类加载到JVM中，加载的时候，就会执行其中的静态初始化块，完成驱动的初始化的相关工作。</p>
</blockquote>
<h4 id="2-建立JDBC和数据库之间的Connection连接"><a href="#2-建立JDBC和数据库之间的Connection连接" class="headerlink" title="2.建立JDBC和数据库之间的Connection连接"></a>2.建立JDBC和数据库之间的Connection连接</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">这里需要提供：数据库所处于的ip:127.0.0.1(本地)</span><br><span class="line">数据库端口号：3306(mysql专用端口号)</span><br><span class="line">数据库名称mysql(根据自己数据库中的名称填写)</span><br><span class="line">编码方式UTF-8</span><br><span class="line">账号 root</span><br><span class="line">密码 1234(根据数据库密码填写)</span><br></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Connection c = DriverManager.getConnection(<span class="string">&quot;jdbc:mysql://127.0.0.1:3306/mysql?characterEncoding=UTF-8&quot;</span>, <span class="string">&quot;root&quot;</span>, <span class="string">&quot;1234&quot;</span>);</span><br></pre></td></tr></table></figure>

<blockquote>
<p>Connection是与特定数据库连接会话的接口，使用的时候需要导包，而且必须在程序结束的时候将其关闭。getConnection方法也需要捕获SQLException异常。<br>因为在进行数据库的增删改查的时候都需要与数据库建立连接，所以可以在项目中建立连接携程一个工具方法，用的时候直接调用即可：</p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">* 取得数据库的连接</span></span><br><span class="line"><span class="comment">* <span class="doctag">@return</span> 一个数据库的连接</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> Connection <span class="title">getConnection</span><span class="params">()</span></span>&#123;</span><br><span class="line">    Connection conn = <span class="keyword">null</span>;</span><br><span class="line">    <span class="keyword">try</span> &#123;</span><br><span class="line">       <span class="comment">//初始化驱动类com.mysql.jdbc.Driver</span></span><br><span class="line">       Class.forName(<span class="string">&quot;com.mysql.jdbc.Driver&quot;</span>);</span><br><span class="line">       conn = DriverManager.getConnection(<span class="string">&quot;jdbc:mysql://127.0.0.1:3306/mysql?characterEncoding=UTF-8&quot;</span>,<span class="string">&quot;root&quot;</span>, <span class="string">&quot;1234&quot;</span>); </span><br><span class="line">       <span class="comment">//该类就在 mysql-connector-java-5.0.8-bin.jar中,如果忘记了第一个步骤的导包，就会抛出ClassNotFoundException</span></span><br><span class="line">       &#125; <span class="keyword">catch</span> (ClassNotFoundException e) &#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">       &#125;<span class="keyword">catch</span> (SQLException e) &#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">       &#125;</span><br><span class="line">   <span class="keyword">return</span> conn； </span><br><span class="line"> &#125;</span><br></pre></td></tr></table></figure>

<h4 id="3-创建Statement或者PreparedStatement接口，执行SQL语句"><a href="#3-创建Statement或者PreparedStatement接口，执行SQL语句" class="headerlink" title="3.创建Statement或者PreparedStatement接口，执行SQL语句"></a>3.创建Statement或者PreparedStatement接口，执行SQL语句</h4><blockquote>
<p>使用Statement接口<br>    Statement接口创建之后，可以执行SQL语句，完成对数据库的增删改查。其中，增删改只需要改变SQL语句的内容就能完成，然而查询略显复杂。在Statement中使用字符串拼接的方式，该方式存在语句复杂，容易犯错等缺点，具体在下文中的对比中介绍。所以Statement在实际过程中使用的非常的少，所以具体的我们放在PreparedStatement里详细介绍。</p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">Statement s = conn.createStatement();</span><br><span class="line"><span class="comment">// 准备sql语句</span></span><br><span class="line"><span class="comment">// 注意： 字符串要用单引号&#x27;</span></span><br><span class="line">String sql = <span class="string">&quot;insert into t_courses values(null,&quot;</span>+<span class="string">&quot;&#x27;数学&#x27;)&quot;</span>;</span><br><span class="line"><span class="comment">//在statement中使用字符串拼接的方式，这种方式存在诸多问</span></span><br><span class="line">s.execute(sql);</span><br><span class="line">System.out.println(<span class="string">&quot;执行插入语句成功&quot;</span>);</span><br></pre></td></tr></table></figure>

<blockquote>
<p>使用PreparedStatement接口<br>    与Statement一样，PreparedStatement也是用来执行sql语句的与创建Statement不同的是，需要根据sql语句创建PreparedStatement.除此之外，还能够通过设置参数，指定相应的值，而不是Statement那种使用字符串拼接。</p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">* 添加课程</span></span><br><span class="line"><span class="comment">* <span class="doctag">@param</span> courseName 课程名称</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">addCourse</span><span class="params">(String courseName)</span></span>&#123;</span><br><span class="line">   String sql = <span class="string">&quot;insert into t_course(course_name) values(?)&quot;</span>;</span><br><span class="line">   <span class="comment">//该语句为每个 IN 参数保留一个问号（“？”）作为占位符</span></span><br><span class="line">   Connection conn = <span class="keyword">null</span>; <span class="comment">//和数据库取得连接</span></span><br><span class="line">   PreparedStatement pstmt = <span class="keyword">null</span>; <span class="comment">//创建statement</span></span><br><span class="line">   <span class="keyword">try</span>&#123;</span><br><span class="line">         conn = DbUtil.getConnection();</span><br><span class="line">         pstmt = (PreparedStatement) conn.prepareStatement(sql);</span><br><span class="line">         pstmt.setString(<span class="number">1</span>, courseName); <span class="comment">//给占位符赋值</span></span><br><span class="line">         pstmt.executeUpdate(); <span class="comment">//执行</span></span><br><span class="line">   &#125;<span class="keyword">catch</span>(SQLException e)&#123;</span><br><span class="line">         e.printStackTrace();</span><br><span class="line">   &#125;</span><br><span class="line">   <span class="keyword">finally</span>&#123;</span><br><span class="line">      DbUtil.close(pstmt);</span><br><span class="line">      DbUtil.close(conn); <span class="comment">//必须关闭</span></span><br><span class="line">   &#125;</span><br><span class="line"> &#125;</span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">* 删除课程</span></span><br><span class="line"><span class="comment">* <span class="doctag">@param</span> courseId </span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">delCourse</span><span class="params">(<span class="keyword">int</span> courseId)</span></span>&#123;</span><br><span class="line">    String sql = <span class="string">&quot;delete from t_course where course_id = ?&quot;</span>;</span><br><span class="line">    Connection conn = <span class="keyword">null</span>;</span><br><span class="line">    PreparedStatement pstmt = <span class="keyword">null</span>;</span><br><span class="line">    <span class="keyword">try</span> &#123;</span><br><span class="line">        conn = DbUtil.getConnection();</span><br><span class="line">        pstmt = (PreparedStatement) conn.prepareStatement(sql);</span><br><span class="line">        pstmt.setInt(<span class="number">1</span>, courseId);</span><br><span class="line">        pstmt.executeUpdate();</span><br><span class="line">    &#125; <span class="keyword">catch</span> (SQLException e) &#123;</span><br><span class="line">       <span class="comment">// <span class="doctag">TODO:</span> handle exception</span></span><br><span class="line">        e.printStackTrace(); </span><br><span class="line">    &#125;<span class="keyword">finally</span>&#123;</span><br><span class="line">       DbUtil.close(pstmt);</span><br><span class="line">       DbUtil.close(conn); <span class="comment">//必须关闭</span></span><br><span class="line">     &#125;</span><br><span class="line"> &#125;</span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">* 修改课程</span></span><br><span class="line"><span class="comment">* <span class="doctag">@param</span> courseId</span></span><br><span class="line"><span class="comment">* <span class="doctag">@param</span> courseName</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"> </span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">modifyCourse</span><span class="params">(<span class="keyword">int</span> courseId,String courseName)</span></span>&#123;</span><br><span class="line">    String sql = <span class="string">&quot;update t_course set course_name =? where course_id=?&quot;</span>;</span><br><span class="line">    Connection conn = <span class="keyword">null</span>;</span><br><span class="line">    PreparedStatement pstmt = <span class="keyword">null</span>;</span><br><span class="line">    <span class="keyword">try</span> &#123;</span><br><span class="line">        conn = DbUtil.getConnection();</span><br><span class="line">        pstmt = (PreparedStatement) conn.prepareStatement(sql);</span><br><span class="line">        pstmt.setString(<span class="number">1</span>, courseName); <span class="comment">//利用Preparedstatement的set方法给占位符赋值</span></span><br><span class="line">        pstmt.setInt(<span class="number">2</span>, courseId);</span><br><span class="line">        pstmt.executeUpdate();</span><br><span class="line">      &#125; <span class="keyword">catch</span> (SQLException e) &#123;</span><br><span class="line">           <span class="comment">// <span class="doctag">TODO:</span> handle exception</span></span><br><span class="line">           e.printStackTrace();</span><br><span class="line">      &#125;<span class="keyword">finally</span>&#123;</span><br><span class="line">          DbUtil.close(pstmt);</span><br><span class="line">          DbUtil.close(conn); <span class="comment">//必须关闭</span></span><br><span class="line">      &#125; </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>由上面的增删改程序可以看出，他们的代码都是大同小异的，主要是SQL语句存在差异，其他的地方几乎是完全相同的。其中有几个地方需要注意：<br>1.使用PreparedStatement时，它的SQL语句不在采用占位符的方式。”?”在这里起到了占位符的作用。这种方式除了避免了Statement拼接字符串的繁琐之外。还能够提高性能。每次SQL语句都是一样的，数据库就不会再次编译，这样能够显著提高性能。</p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">String sql = <span class="string">&quot;update t_course set course_name =? where course_id=?&quot;</span>;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>后面需要用到PreparedStatement接口创建的pstmt的set方法给占位符进行复制。注意一点，这里的参数索引是从1开始的，在添加的过程中，如果添加的数据量比较大的话，可以用批量添加。PreparedStatement接口提供了相应的批量操作的方法</p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">pstmt = (PreparedStatement) conn.prepareStatement(sql);</span><br><span class="line">pstmt.setString(<span class="number">1</span>, courseName); <span class="comment">//利用Preparedstatement的set方法给占位符赋值</span></span><br><span class="line">pstmt.setInt(<span class="number">2</span>, courseId);</span><br><span class="line">pstmt.executeUpdate();</span><br></pre></td></tr></table></figure>

<blockquote>
<p>增删改都使用pstmt.executeUpdate()语句进行SQL语句的提交，下文的查询会有所不同，请注意</p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i&lt;<span class="number">100</span>;i++)&#123; </span><br><span class="line">     pstmt.setInt(<span class="number">1</span>,<span class="number">8000</span>+i);</span><br><span class="line">     pstmt.setString(<span class="number">2</span>,<span class="string">&quot;赵_&quot;</span>+i);</span><br><span class="line">     pstmt.addBatch();</span><br><span class="line">     <span class="comment">//批量更新</span></span><br><span class="line">     <span class="keyword">if</span>(i%<span class="number">10</span>==<span class="number">0</span>)&#123;</span><br><span class="line">        pstmt.executeBatch()； </span><br><span class="line">     &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<blockquote>
<p>下面我们来看稍显麻烦一点的查询操作</p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">* 查询课程</span></span><br><span class="line"><span class="comment">* <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> List&lt;Course&gt; <span class="title">findCourseList</span><span class="params">()</span></span>&#123;</span><br><span class="line">     String sql = <span class="string">&quot;select * from t_course order by course_id&quot;</span>;</span><br><span class="line">     Connection conn = <span class="keyword">null</span>;</span><br><span class="line">     PreparedStatement pstmt = <span class="keyword">null</span>;</span><br><span class="line">     ResultSet rs = <span class="keyword">null</span>;</span><br><span class="line">     <span class="comment">//创建一个集合对象用来存放查询到的数据</span></span><br><span class="line">     List&lt;Course&gt; courseList = <span class="keyword">new</span> ArrayList&lt;&gt;();</span><br><span class="line">     <span class="keyword">try</span> &#123;</span><br><span class="line">         conn = DbUtil.getConnection();</span><br><span class="line">         pstmt = (PreparedStatement) conn.prepareStatement(sql);</span><br><span class="line">         rs = (ResultSet) pstmt.executeQuery();</span><br><span class="line">         <span class="keyword">while</span> (rs.next())&#123;</span><br><span class="line">            <span class="keyword">int</span> courseId = rs.getInt(<span class="string">&quot;course_id&quot;</span>);</span><br><span class="line">            String courseName = rs.getString(<span class="string">&quot;course_name&quot;</span>);</span><br><span class="line">            <span class="comment">//每个记录对应一个对象</span></span><br><span class="line">            Course course = <span class="keyword">new</span> Course();</span><br><span class="line">            course.setCourseId(courseId);</span><br><span class="line">            course.setCourseName(courseName);</span><br><span class="line">            <span class="comment">//将对象放到集合中</span></span><br><span class="line">             courseList.add(course);</span><br><span class="line">        &#125;</span><br><span class="line">      &#125; <span class="keyword">catch</span> (SQLException e) &#123;</span><br><span class="line">        <span class="comment">// <span class="doctag">TODO:</span> handle exception</span></span><br><span class="line">          e.printStackTrace();</span><br><span class="line">     &#125;<span class="keyword">finally</span>&#123;</span><br><span class="line">           DbUtil.close(pstmt);</span><br><span class="line">           DbUtil.close(conn); <span class="comment">//必须关闭</span></span><br><span class="line">   	 &#125;</span><br><span class="line">    <span class="keyword">return</span> courseList; </span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<blockquote>
<p>查询操作使用executeQuery()进行更新。其他相关问题放在第四步（处理和显示结果）中解析。</p>
</blockquote>
<h4 id="4-处理和显示结果"><a href="#4-处理和显示结果" class="headerlink" title="4.处理和显示结果"></a>4.处理和显示结果</h4><blockquote>
<p>执行查询语句，并把结果返回给集合ResultSet</p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">ResultSet rs = s.executeQuery(sql);</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<blockquote>
<p>利用while(ResultSet.next()){…}循环将集合ResultSet中结果遍历出来。</p>
<p>ResultSet.getXX();这里的get方法的括号里面可以填属性值，如下图代码中的course_id，还可以填该属性在数据表中的序号，从1开始编码，例如：course_id在我的t_courses数据表中位于第一列，所以执行get方法的时候，我除了代码段中的写法外，还可以这样写int courseId = rs.getInt(1);但是不推荐使用序号这种方式，因为一段数据表中个别属性值发生顺序变化就会导致这里出错，而使用属性名则不会出现这样的问题。</p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">while</span> (rs.next())&#123;</span><br><span class="line">    <span class="keyword">int</span> courseId = rs.getInt(<span class="string">&quot;course_id&quot;</span>);</span><br><span class="line">    String courseName = rs.getString(<span class="string">&quot;course_name&quot;</span>);</span><br><span class="line">    <span class="comment">//每个记录对应一个对象</span></span><br><span class="line">    Course course = <span class="keyword">new</span> Course();</span><br><span class="line">    <span class="comment">//在我的项目中创建了course类，其中定义了set方法，所以这里将查询到的值传给了course，也可以直接打印到控制台</span></span><br><span class="line">    course.setCourseId(courseId);</span><br><span class="line">    course.setCourseName(courseName);</span><br><span class="line">    <span class="comment">//将对象放到集合中</span></span><br><span class="line">    courseList.add(course);</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<blockquote>
<p>还有一点需要说明的是：</p>
<p>​        因为在我的项目中创建了course类，其中定义set方法，所以在这里将查询到的值传给了course，你也可以直接打印语句将CourseId和CourseName打印到控制台。</p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">course.setCourseId(courseId);</span><br><span class="line">course.setCourseName(courseName); </span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h4 id="5-释放资源"><a href="#5-释放资源" class="headerlink" title="5.释放资源"></a>5.释放资源</h4><blockquote>
<p>在JDBC编码的过程中我们创建了Connection、ResultSet等资源，这些资源在使用完毕之后一定要进行关闭的。关闭的过程中遵循从里到外的原则。因为在增删改查的操作中都要用到这样的关闭操作，为了是代码简单，增加其复用性，这里我将这些关闭的操作写成一个方法和建立连接的方法一起放到一个工具类中。</p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 封装三个关闭方法</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param</span> pstmt</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">close</span><span class="params">(PreparedStatement pstmt)</span></span>&#123;</span><br><span class="line">    <span class="keyword">if</span>(pstmt != <span class="keyword">null</span>)&#123; <span class="comment">//避免出现空指针异常</span></span><br><span class="line">        <span class="keyword">try</span>&#123;</span><br><span class="line">            pstmt.close();</span><br><span class="line">        &#125;<span class="keyword">catch</span>(SQLException e)&#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">close</span><span class="params">(Connection conn)</span></span>&#123;</span><br><span class="line">    <span class="keyword">if</span>(conn != <span class="keyword">null</span>)&#123;</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            conn.close();</span><br><span class="line">        &#125; <span class="keyword">catch</span> (SQLException e) &#123;</span><br><span class="line">            <span class="comment">// <span class="doctag">TODO:</span> handle exception</span></span><br><span class="line">            e.printStackTrace();</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">close</span><span class="params">(ResultSet rs)</span></span>&#123;</span><br><span class="line">    <span class="keyword">if</span> (rs != <span class="keyword">null</span>) &#123;</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            rs.close();</span><br><span class="line">        &#125; <span class="keyword">catch</span> (SQLException e) &#123;</span><br><span class="line">            <span class="comment">// <span class="doctag">TODO:</span> handle exception</span></span><br><span class="line">            e.printStackTrace();</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h5 id="Statement和PreparedStatement的异同及优缺点"><a href="#Statement和PreparedStatement的异同及优缺点" class="headerlink" title="Statement和PreparedStatement的异同及优缺点"></a>Statement和PreparedStatement的异同及优缺点</h5><blockquote>
<p>同：两者都是用来执行SQL语句的</p>
<p>异：PreparedStatement需要根据Sql语句来创建，它能够通过设置参数，指定相应的值，不是像Statement那样使用字符串拼接的方式。</p>
<p>PreparedStatement的优点：</p>
<p>1、其使用参数设置，可读性好，不易记错。在Statement中使用字符串拼接，可读性和维护性比较差。</p>
<p>2、其具有预编译机制，性能比Statement更好。</p>
<p>3、其能够有效防止SQL注入攻击。</p>
</blockquote>
<h5 id="execute和executeUpdate的区别-gt"><a href="#execute和executeUpdate的区别-gt" class="headerlink" title="execute和executeUpdate的区别&gt;"></a>execute和executeUpdate的区别&gt;</h5><blockquote>
<p>同：二者都能够执行增加、删除、修改等操作。</p>
<p>异：1、execute可以执行查询语句，然后通过getResult将结果去出来。executeUpdate不能执行查询语句。</p>
<p>​        2、execute返回Boolean类型，true表示执行的是查询的语句，fasle表示执行的是insert、delete、update等语句。</p>
<p>​             executeUpdate的返回值是int，表示有多少条数据受到了影响。</p>
</blockquote>

    </div>

    
    
    
        

<div>
<ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者： </strong>Demon
  </li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="https://gitee.com/Demon_wang/blog.git/post/42809/" title="JDBC详细介绍">https://gitee.com/Demon_wang/blog.git/post/42809/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" rel="noopener" target="_blank"><i class="fab fa-fw fa-creative-commons"></i>BY-NC-SA</a> 许可协议。转载请注明出处！
  </li>
</ul>
</div>


      <footer class="post-footer">

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/blog/post/4a17b156/" rel="prev" title="Hello World">
      <i class="fa fa-chevron-left"></i> Hello World
    </a></div>
      <div class="post-nav-item"></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#JDBC"><span class="nav-text">JDBC</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#JDBC%E7%BC%96%E7%A8%8B%E6%AD%A5%E9%AA%A4"><span class="nav-text">JDBC编程步骤</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#1-%E8%A3%85%E8%BD%BD%E7%9B%B8%E5%BA%94%E7%9A%84%E6%95%B0%E6%8D%AE%E5%BA%93%E7%9A%84JDBC%E9%A9%B1%E5%8A%A8%E5%B9%B6%E8%BF%9B%E8%A1%8C%E5%88%9D%E5%A7%8B%E5%8C%96"><span class="nav-text">1.装载相应的数据库的JDBC驱动并进行初始化</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-%E5%BB%BA%E7%AB%8BJDBC%E5%92%8C%E6%95%B0%E6%8D%AE%E5%BA%93%E4%B9%8B%E9%97%B4%E7%9A%84Connection%E8%BF%9E%E6%8E%A5"><span class="nav-text">2.建立JDBC和数据库之间的Connection连接</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#3-%E5%88%9B%E5%BB%BAStatement%E6%88%96%E8%80%85PreparedStatement%E6%8E%A5%E5%8F%A3%EF%BC%8C%E6%89%A7%E8%A1%8CSQL%E8%AF%AD%E5%8F%A5"><span class="nav-text">3.创建Statement或者PreparedStatement接口，执行SQL语句</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#4-%E5%A4%84%E7%90%86%E5%92%8C%E6%98%BE%E7%A4%BA%E7%BB%93%E6%9E%9C"><span class="nav-text">4.处理和显示结果</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#5-%E9%87%8A%E6%94%BE%E8%B5%84%E6%BA%90"><span class="nav-text">5.释放资源</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#Statement%E5%92%8CPreparedStatement%E7%9A%84%E5%BC%82%E5%90%8C%E5%8F%8A%E4%BC%98%E7%BC%BA%E7%82%B9"><span class="nav-text">Statement和PreparedStatement的异同及优缺点</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#execute%E5%92%8CexecuteUpdate%E7%9A%84%E5%8C%BA%E5%88%AB-gt"><span class="nav-text">execute和executeUpdate的区别&gt;</span></a></li></ol></li></ol></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="Demon"
      src="/blog/images/Demon.jpg">
  <p class="site-author-name" itemprop="name">Demon</p>
  <div class="site-description" itemprop="description">博客</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/blog/archives/">
        
          <span class="site-state-item-count">2</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/Demon-0314" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;Demon-0314" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:18579545525@163.com" title="邮箱 → mailto:18579545525@163.com" rel="noopener" target="_blank"><i class="fa fa-envelope fa-fw"></i>邮箱</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://weibo.com/yourname" title="微博 → https:&#x2F;&#x2F;weibo.com&#x2F;yourname" rel="noopener" target="_blank"><i class="fab fa-weibo fa-fw"></i>微博</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://plus.google.com/yourname" title="谷歌 → https:&#x2F;&#x2F;plus.google.com&#x2F;yourname" rel="noopener" target="_blank"><i class="fab fa-google fa-fw"></i>谷歌</a>
      </span>
  </div>


  <div class="links-of-blogroll motion-element">
    <div class="links-of-blogroll-title"><i class="fa fa-link fa-fw"></i>
      Links
    </div>
    <ul class="links-of-blogroll-list">
        <li class="links-of-blogroll-item">
          <a href="http://yoursite.com/" title="http:&#x2F;&#x2F;yoursite.com" rel="noopener" target="_blank">Title</a>
        </li>
    </ul>
  </div>

      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Demon</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-area"></i>
    </span>
      <span class="post-meta-item-text">站点总字数：</span>
    <span title="站点总字数">8k</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
      <span class="post-meta-item-text">站点阅读时长 &asymp;</span>
    <span title="站点阅读时长">7 分钟</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Gemini</a> 强力驱动
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/blog/lib/anime.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js"></script>
  <script src="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.js"></script>
  <script src="/blog/lib/velocity/velocity.min.js"></script>
  <script src="/blog/lib/velocity/velocity.ui.min.js"></script>

<script src="/blog/js/utils.js"></script>

<script src="/blog/js/motion.js"></script>


<script src="/blog/js/schemes/pisces.js"></script>


<script src="/blog/js/next-boot.js"></script>




  




  
<script src="/blog/js/local-search.js"></script>













  

  

</body>
</html>
